Questions
17 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
17 / 50

What is the difference between :link and :visited?

Understanding :link vs :visited Pseudo-Classes in CSS

In CSS, :link and :visited are pseudo-classes used to style anchor (<a>) elements depending on whether the link has been visited by the user.

Key Differences
  1. 1

    :link – Targets all unvisited links. These are links the user has not clicked on yet.

  2. 2

    :visited – Targets links that the user has already visited. Browsers restrict the styles that can be applied to protect user privacy.

  3. 3

    Use :link and :visited to visually differentiate unvisited and visited links for better navigation experience.

Example: :link vs :visited

In this example, links the user has not visited appear blue (:link), and links that have been visited appear purple (:visited). Hovering over any link changes its color and adds an underline.

Best Practices
  1. 1

    Always use :link and :visited together to provide clear navigation cues.

  2. 2

    Avoid using styles that violate privacy restrictions; only certain properties like color can be applied to :visited.

  3. 3

    Combine with :hover and :active for consistent interactive feedback.

  4. 4

    Test link styling across browsers as handling of visited links may vary.

Difficulty: 3/10
Topics: CSS pseudo-classes, link state styling, visual feedback

Scenario Questions

0-2 years experience
  1. 1

    You're building a simple navigation bar and notice that all links look the same—even after clicking them. How would you fix it using :link and :visited?

  2. 2

    A junior designer says they want visited links to turn red and bold. What’s the problem with that request, and how would you explain it?

  3. 3

    What happens if you write a CSS rule for :visited but forget to define :link? Do the links still look different after being clicked?

2-5 years experience
  1. 1

    Our users report that some links in the footer appear dim after clicking, but others don’t. You’ve checked the CSS—:visited is set, but it’s not working. What could be going wrong?

  2. 2

    We’re building a documentation site with hundreds of internal links. Some teams are using :visited to indicate ‘read’ content, but accessibility audits are flagging it. How would you debug and fix this?

  3. 3

    A feature flag turns on a custom theme that changes link colors. After the update, users say they can’t tell which links they’ve visited. What’s the most likely cause, and how do you verify it?

5-8 years experience
  1. 1

    We’re designing a global navigation component used across 50+ micro-frontends. How do you ensure consistent :link and :visited behavior without breaking privacy restrictions or causing layout shifts?

  2. 2

    Our analytics show users are clicking the same links repeatedly—could :visited styling be contributing to confusion? How would you redesign the feedback system to improve usability without violating browser security policies?

  3. 3

    A legacy CSS file uses :visited to change background images. It’s causing performance issues and layout thrashing. How would you refactor this without losing the visual feedback users rely on?

8+ years experience
  1. 1

    We’re migrating from a monolith to a component library, and legacy code relies on :visited for user progress tracking. How do you deprecate this safely without breaking user expectations or introducing privacy risks?

  2. 2

    Our design system allows teams to customize link states. How do you enforce a policy around :visited styling that balances brand flexibility, accessibility, and browser security constraints across 200+ products?

  3. 3

    A competitor uses :visited to track user behavior via CSS-based telemetry. How would you architect a privacy-compliant alternative that still provides engagement insights without exposing browsing history?

Follow-up Questions

  • What happens if you style :visited before :link?
  • Why can't you change the font size of a :visited link?
  • How would you test if your link styles are working correctly across browsers?